require "tests/console/console";

class SchoolConsole < Console
  
  Student = Struct.new(:id, :name, :age);
  Classroom = Struct.new(:id, :name, :students);
  students_id = 0;
  classrooms_id = 0;
  
  index "1: Inserir Aluno",
    "2: Inserir Classe",
    "3: Listar Alunos",
    "4: Listar Classes",
    "0: Sair",
    "Opcao: "
  
  def method_missing(command)
    puts "Opcao Invalida"
  end
  
  option 1 do
    puts "Inserindo Aluno";
    params = ask_params :name => "Nome:", :age => "Idade:";
    @students ||= [];
    @students << Student.new((students_id += 1), params[:name], params[:age]);
  end
  
  option 2 do
    puts "Inserindo Classe";
    params = ask_params :name => "Nome:";
    @classrooms ||= [];
    @classrooms << Classroom.new((classrooms_id += 1), params[:name], []);
  end
  
  option 3 do
    puts "Listando Alunos";
    @students.each do |student|
      puts "#{student.id}: #{student.name} - #{student.age}";
    end
  end
  
  option 4 do
    puts "Listando Classes";
    @classrooms.each do |classroom|
      students = classroom.students.map{|s| s.name}.join(" ");
      puts "#{classroom.id}: #{classroom.name} - #{classroom} - #{students}";
    end
  end
  
  option 0 do
    puts "Saindo..."
    exit;
  end
  
end

SchoolConsole.start